package com.example.analysis.service.impl;

import com.example.analysis.entity.Supervision;
import com.example.analysis.entity.Supervision;
import com.example.analysis.mapper.SupervisionDao;
import com.example.analysis.service.SupervisionService;
import com.example.analysis.utils.Response;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SupervisionServiceImpl implements SupervisionService {

    @Resource
    private SupervisionDao supervisionDao;

    @Override
    public Response<Supervision> insert(Supervision aSupervision) {
        try {
            supervisionDao.insert(aSupervision);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Supervision> getById(String SupervisionId) {
        Supervision aSupervision = supervisionDao.selectByPrimaryKey(SupervisionId);
        if (aSupervision != null) {
            return new Response<>(true, "Success", aSupervision);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<List<Supervision>> getByName(String supervisionName) {
        List<Supervision> SupervisionList=supervisionDao.getName(supervisionName);
        if (SupervisionList != null) {
            return new Response<>(true, "Success", SupervisionList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
